package io.renren.modules.course.service.impl;

import io.renren.modules.course.entity.CourseSmallClassification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.course.dao.CourseSmallDao;
import io.renren.modules.course.entity.CourseSmallEntity;
import io.renren.modules.course.service.CourseSmallService;


@Service("courseSmallService")
public class CourseSmallServiceImpl extends ServiceImpl<CourseSmallDao, CourseSmallEntity> implements CourseSmallService {

    @Autowired
    CourseSmallDao courseSmallDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<CourseSmallEntity> page = this.selectPage(
                new Query<CourseSmallEntity>(params).getPage(),
                new EntityWrapper<CourseSmallEntity>()
                .eq("teacher_id",params.get("userId"))


        );

        return new PageUtils(page);
    }

    @Override
    public void online(Map map) {
        courseSmallDao.online(map);
    }

    @Override
    public List<CourseSmallClassification> getCourseSmallClassification(int id) {

        List<CourseSmallClassification> firstClassificationList =courseSmallDao.getCourseSmallClassification(id);

        for(CourseSmallClassification courseSmallClassification : firstClassificationList){

            List<CourseSmallClassification> secondClassificationList = this.getCourseSmallClassification(courseSmallClassification.getId());

            if(secondClassificationList.size() !=0){
                courseSmallClassification.setChildClassificationList(secondClassificationList);
            }
        }

        return firstClassificationList;
    }

    @Override
    public List getCourseSmallByTitleLike(String word) {
        return courseSmallDao.getCourseSmallByTitleLike(word);
    }

}
